package inner_class;

public class ShareFieldDemo {
    private String name;

    void test() throws InterruptedException {
        String abc = "abc";
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                // 直接对上层类的字段赋值
                name = "123";
//            abc = null; // 不能对局部变量操作，因为局部变量必须要是final，并且会在匿名类中创建一个字段来存储这个值
                System.out.println("abc -> " + abc);
            }
        });
        thread.start();
//        thread.join();
        System.out.println("abc -> " + abc);
    }

    public static void main(String[] args) throws InterruptedException {
        ShareFieldDemo demo = new ShareFieldDemo();
        demo.test();
        System.out.println("name -> " + demo.name);
    }
}
